// 请求
import axios from 'axios'
import serverIp from '../../../config/serverIp'
import qs from 'qs'
axios.defaults.baseURL = serverIp.serverArgument + serverIp.serverHost + ':' + serverIp.serverPort
axios.defaults.withCredentials = false // 解决axios post不能传参

const resource = {
  state: {
    // 资源列表
    resourceListSta: [],
    // 编辑资源模态框
    resourceEditModalSta: false,
    // 当前选中的资源
    resourceOneSta: {}
  },
  mutations: {
    // 资源列表添加数据
    resourceListMut: (state, payload) => {
      state.resourceListSta = payload
    },
    // 编辑资源模态框状态
    resourceEditModalMut: (state, payload) => {
      state.resourceEditModalSta = payload.state
    },
    // 设置当前选中资源
    resourceOneMut: (state, payload) => {
      state.resourceOneSta = payload.state
    }
  },
  actions: {
    // 获取资源列表
    roleListAct: (context) => {
      let obj = qs.stringify({})
      axios.post('/acl_resource/list', obj).then(res => {
        let userList = res.data
        context.commit('resourceListMut', userList)
      })
    }
  }
}
export default resource
